package com.anche.cywebnew.Controller.securityManager;


import com.anche.cywebnew.Pojo.securityManager.SecurityLog;
import com.anche.cywebnew.Service.securityManager.SecurityLogService;
import com.github.pagehelper.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/security/securityLog")
public class SecurityLogController {

    private static final Logger logger = LoggerFactory.getLogger(SecurityLogController.class);

    @Autowired
    private SecurityLogService securityLogService;

    @RequestMapping("/manager")
    public String manager(){
        return "securityManager/securityLog";
    }

    @RequestMapping("/securityLogPager")
    @ResponseBody
    public Object getSecurityLogPager(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit,
                                   SecurityLog securityLog) {
        Map<String, Object> map = new HashMap<>();
        try {
            Page<SecurityLog> securityLogPage = securityLogService.getSecurityLogPager(page, limit, securityLog);
            logger.info("<查询安全日志列表成功>");
            map.put("code", "0");
            map.put("count", securityLogPage.getTotal());
            map.put("msg", "查询成功");
            map.put("data", securityLogPage.getResult());
        } catch (Exception e) {
            logger.error("<查询安全日志列表异常:[{}]>", e.getMessage());
            e.printStackTrace();
            map.put("code", "1");
            map.put("msg", e.getMessage());
        }
        return map;
    }

    @RequestMapping("/securityLogStat")
    @ResponseBody
    public Object getSecurityLogStat() {
        Map<String, Object> map = new HashMap<>();
        try {
            List<Map<String, String>> statMaps = securityLogService.getSecurityLogStat();
            logger.info("<查询安全日志列表成功>");
            map.put("code", "0");
            map.put("msg", "查询成功");
            map.put("data", statMaps);
        } catch (Exception e) {
            logger.error("<查询安全日志列表异常:[{}]>", e.getMessage());
            e.printStackTrace();
            map.put("code", "1");
            map.put("msg", e.getMessage());
        }
        return map;
    }
}
